package com.zyl.swaggerjavadoc;

import cn.willingxyz.restdoc.core.config.RestDocConfig;
import cn.willingxyz.restdoc.springswagger2.EnableSwagger2;
import cn.willingxyz.restdoc.swagger.common.SwaggerUIConfiguration;
import cn.willingxyz.restdoc.swagger2.RestDocConfigSwagger2Ext;
import com.zyl.swaggerjavadoc.ext.TestSwaggerFilter;
import lombok.var;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;

@SpringBootApplication
@EnableSwagger2
public class SwaggerJavadocApplication {

    public static void main(String[] args) {
        SpringApplication.run(SwaggerJavadocApplication.class, args);
    }


    @Bean
    RestDocConfig _swaggerConfig() {
        return RestDocConfig.builder()
                .apiTitle("rest doc title")
                .apiDescription("rest doc desc")
                .apiVersion("api version")
                .fieldPrefix("_")
                .tagDescriptionAsName(true)
                .hideEmptyController(true)
                .resolveJavaDocAsTypeName(false)
//                .httpBasicAuth(new RestDocConfig.HttpBasicAuth("restdoc","restdoc"))
                .packages(Arrays.asList("cn.willingxyz.restdoc.spring.examples"))
                .servers(Arrays.asList(RestDocConfig.Server.builder().description("url desc").url("https://localhost:8045").build(),
                        RestDocConfig.Server.builder().description("second").url("http://localhost:8045").build()))
                .build();
    }

    @Bean
    RestDocConfigSwagger2Ext restDocConfigSwagger2Ext() {
        return RestDocConfigSwagger2Ext.builder()
                .swaggerFilters(Arrays.asList(new TestSwaggerFilter()))
                .build();
    }

    @Bean
    SwaggerUIConfiguration _swaggerUIConfiguration() {
        var uiConfig = new SwaggerUIConfiguration();
//        uiConfig.setDefaultModelRendering("model");
        uiConfig.setDefaultModelExpandDepth(100);
//        uiConfig.setDocExpansion("full");
        return uiConfig;
    }
}
